package awesome.mail;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import awesome.authenticate.Authenticate;


class MailSender {
    public static void sendMail(String messageToAll, String To) throws Exception{
    	
      
    	Authenticate authenticator = new Authenticate();
		
      Properties props = new Properties();
		props.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName());
		props.setProperty("mail.smtp.auth", "true");

      props.setProperty("mail.transport.protocol", "smtp");
      props.setProperty("mail.host", "mail.winona.edu");
     
      Session mailSession = Session.getDefaultInstance(props, authenticator);
      Transport transport = mailSession.getTransport();

      MimeMessage message = new MimeMessage(mailSession);
      message.setSubject("Awesome Auctions");
      message.setContent(messageToAll, "text/html");
      message.setFrom(new InternetAddress("dshrestha06@winona.edu"));
      message.addRecipient(Message.RecipientType.TO,
           new InternetAddress(To));

      transport.connect();
      transport.sendMessage(message,
          message.getRecipients(Message.RecipientType.TO));
      transport.close();
    }
}